<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019\3\7 0007
 * Time: 14:29
 */

namespace app\service;

use think\facade\Db;

class xcxService
{
    //小区列表
    public function communityList()
    {
        $list = Db::name('community')->select();
        return $list;
    }
    //组团列表
    public function groupList($community_id)
    {
        //$communityinfo=Db::table("community")->where("id",$community_id)->find();
        $list = Db::name('roominfo')->distinct('group')->where('community_id',$community_id)->column('group');
        //$list = array_unique($list);
        return $list;
    }
    //幢数列表
    public function buildingList($group,$community_id)
    {
        //$communityinfo=Db::table("community")->where("id",$community_id)->find();
        $list = Db::name('roominfo')->distinct('building')->where('group',$group)->where('community_id',$community_id)->order('building')->column('building');
        //$sql="select distinct(building) from roominfo where community_id='$community_id'";
        //$sql=$sql." and zz_group='$group'";
		//$list=Db::query($sql);
        
        return $list;
    }
    //单元列表
    public function unitList($building,$group,$community_id)
    {
        //$communityinfo=Db::table("community")->where("id",$community_id)->find();
        $list = Db::name('roominfo')->distinct('unit')->where('community_id',$community_id)->where('group',$group)->where('building',$building)->column('unit');
        $list = array_unique($list);

        return $list;
    }
    //房屋列表
    public function roomList($unit,$building,$group,$community_id)
    {
        //$communityinfo=Db::table("community")->where("id",$community_id)->find();
        $list = Db::name('roominfo')->where('community_id',$community_id)->where('group',$group)->where('unit',$unit)->where('building',$building)->column('room');
        $list = array_unique($list);
        return $list;
    }
    //模糊查询小区
    public function communityName($communityName)
    {
        $list = Db::name('community')->where('community_name',"like","$communityName%")->select();
        return $list;
    }
	//报事报修类型查询
    public function typeList(){
        return Db::name('repair_type')->order('id asc')->select();
    }
    //g用户显示列表
    public function repairslist($user_id)
    {
        return Db::name('repair')->where('user_id',$user_id)->select();

    }
    //用户投诉显示列表
    public function complaintlist($user_id)
    {
        return Db::name('proposal')->where('user_id',$user_id)->select();

    }
	   //用户投诉显示列表
    public function user($user_id)
    {
       $name = Db::name('room')->where('user_id',$user_id)->find();
		return $name;
    }
   
    //公告小区信息
    public function communityIdName($id){
        return Db::name('community')->where('id',$id)->find();
    }
    //公告信息
    public function notice($id){
        return Db::name('notice')->where('community_id',$id)->select();
    }
	 //小区列表
    public function communityNotice($id)
    {
        $list = Db::name('community')->where('id',$id)->value('community_name');
        return $list;
    }
	//查询保修类型
    public function repairsName($typeid)
    {
       return Db::name('repair_type')->where('id',$typeid)->value('name');

    }
	//添加到家服务列表
	
    public function homeServe($add)
    {
      
  
        return Db::name('homeserve')->insertGetId($add);
    

    }
	//上门服务
    public function homelist($user_id)
    {
        return Db::name('homeserve')->where('user_id',$user_id)->select();

    }
//查询服务类型
    public function homeName($typeid)
    {
       return Db::name('home_type')->where('id',$typeid)->value('name');

    }
	//报事报修类型查询
    public function hometypeList(){
        return Db::name('home_type')->order('id asc')->select();
    }
	//查询保修类型
    public function serveName($typeid)
    {
       return Db::name('home_type')->where('id',$typeid)->value('name');

    }
	//房屋管理
	public function proposalAdd($data)
	{
		return Db::name('room')->insertGetId($data);
	}
	//帐单列表
	public function billList($user_id)
	{
		return Db::name('bill')->where('user_id',$user_id)->where('status','TRADE_SUCCESS')->select();
	}
	//用户绑定房屋列表
	public function roomList1($user_id)
	{
		return Db::name('room')->where('user_id',$user_id)->select();
	}
	//用户绑定房屋列表
	public function delroom($user_id)
	{
		return Db::name('room')->where('id',$user_id)->delete();
	}
	//查询该用户是否已绑定该房屋
	
	public function roomsel($room_id,$user_id)
	{
		return Db::name('room')->where('user_id',$user_id)->where('room_id',$room_id)->find();
	}

    //--------------bill----------------
    public function getroominfo($community_id,$group,$building,$unit,$room){
        return Db::name("roominfo")
                    ->where("community_id",$community_id)
                    ->where("group",$group)
                    ->where("building",$building)
                    ->where("unit",$unit)
                    ->where("room",$room)
                    ->find();
    }
    public function billRoomIdList($out_room_id){
        return Db::name('bill')
                    ->where('out_room_id',$out_room_id)
                    ->where('status','WAIT_PAYMENT')
                    ->select();
    }
    
    public function cost_type($out_room_id){
        $cost_type = Db::name('bill')->where('out_room_id',$out_room_id)->where('status','WAIT_PAYMENT')->column('cost_type');
        
        return array_unique($cost_type);
    }

    //根据种类查账单
    public function cost_type_bill($out_room_id,$b){
        $cost_type_bill = Db::name('bill')->where('out_room_id',$out_room_id)->where('status','WAIT_PAYMENT')->where('cost_type',$b)->select();
        
        return $cost_type_bill ;
    }

    //获取token
    public function token($community_id){
        $property_id = Db::name('community')->where('community_id',$community_id)->value('property_id');
        return Db::name('property')->where('id',$property_id)->value('accredit');
    }
}